Just-in-time compilation (JIT), also known as dynamic translation, is compilation done during execution of a program or an application at run time, rather than prior to execution. Often JIT involves translation/compilation to native codes for a machine (e.g., a computer), which are then executed directly by one or more processors of the machine.
JIT compilers may be used for generating native codes for Java programs. Java programs may be run on any machine on which a Java virtual machine (JVM) is executing. A Java program includes a plurality of object classes, and each object class can have zero or more methods. When a Java program is executed, the methods of the object classes are invoked and executed.
A java method may be executed in one of two ways. One way is for the NM to execute the method in an interpretive manner. For example, before a Java program is executed, source codes of the program (e.g., the source codes of the methods) is broken down into Java bytecodes. At runtime, the Java interpreter of the JVM interprets the bytecodes of a method, which is a relatively slow process. As an alternative, the NM may choose not to interpret a method, but rather compile the bytecodes of the method down into native codes, e.g., using a JIT compiler at runtime. The JVM then causes the native codes to be executed directly by one or more processors.
Local variables associated with the execution of native codes generated by a JIT compiler often need to be loaded from memory, which is a time consuming process. One way to improve the execution of the native codes generated by the JIT compiler is to maintain often-used local variables in physical registers (e.g., hardware registers) as much as possible. Register allocation is an important optimization process for improving efficiency. For example, a linear scan algorithm can be implemented for register allocation. The linear scan algorithm involves assigning registers to variables in a single linear scan over live intervals of all variables in a program. A live interval of a variable corresponds to a range of instructions starting at a defining instruction and ending at an instruction where the variable is used for the last time. If the live intervals of two variables overlap, the variables cannot reside in a same physical register.